package com.tengol.course.spring.boot.database.jdbc.web;

import com.tengol.course.spring.boot.database.jdbc.common.UserRowMapper;
import com.tengol.course.spring.boot.database.jdbc.entity.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * HelloController
 *
 * @author dongrui
 * @date 2020/5/18 13:33
 */
@RestController
@RequestMapping(value = "/hello")
public class HelloController {

    private JdbcTemplate jdbcTemplate;

    public HelloController(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @GetMapping("/query")
    public User querySql(){
        String sql = "select * from tb_user where id=1";
        return jdbcTemplate.queryForObject(sql, new UserRowMapper());
    }

}
